class Solution:
    def _numSub(self, s: int) -> int:
        return sum(range(1, s+1))

    def numSub(self, s: str) -> int:
        si = 0
        in_range = False
        res = 0
        for i, x in enumerate(s):
            if not in_range and x == '1':
                si = i
                in_range = True
                continue
            if in_range and x != '1':
                length = (i - si)
                res += self._numSub(length)
                in_range = False
        if in_range:
            length = len(s) - si
            res += self._numSub(length)
        return res % (10^9 + 7)


if __name__ == '__main__':
    s = Solution()
    print(s.numSub('11101'))
